package org.desktop.web.client.custom.widget.grid.user.model;

import java.util.HashMap;
import java.util.Map;

import org.desktop.web.shared.domain.entities.User;

import com.sencha.gxt.core.client.IdentityValueProvider;
import com.sencha.gxt.widget.core.client.event.RefreshEvent;
import com.sencha.gxt.widget.core.client.grid.CheckBoxSelectionModel;

public class ModUserAssociationToProjectCheckBoxSelectionModel extends
		CheckBoxSelectionModel<User> {

	private IdentityValueProvider<User> identity;
	Map<Integer, User> selected = new HashMap<Integer, User>();
	Map<Integer, User> unselected = new HashMap<Integer, User>();


	public ModUserAssociationToProjectCheckBoxSelectionModel(
			IdentityValueProvider<User> identity) {
		// TODO Auto-generated constructor stub
		this.identity = identity;
	}


	@Override
	protected void onRefresh(RefreshEvent event) {
		// this code selects all rows when paging if the header checkbox
		// is selected
		if (isSelectAllChecked()) {
			selectAll();
		}
		super.onRefresh(event);
	}

	// @Override
	// protected void onRowClick(RowClickEvent event) {
	// // TODO Auto-generated method stub
	// ModUser user = store.getAll().get(event.getRowIndex());
	//
	// super.onRowClick(event);
	//
	// }

	@Override
	protected void onSelectChange(User model, boolean select) {
		// TODO Auto-generated method stub
		super.onSelectChange(model, select);
		int id = model.getId();
		if (select) {
			selected.put(id, model);
			unselected.remove(id);
		} else {
			unselected.put(id, model);
			selected.remove(id);
		}
	}


	public Map<Integer, User> getSelected() {
		return selected;
	}


	public Map<Integer, User> getUnselected() {
		return unselected;
	}

}
